home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / mus / play / multiplsr.lha / flashywin.c < prev    next >
C/C++ Source or Header  |  1992-09-14  |  8KB  |  286 lines

  1. /*
  2.  * MultiPlayer
  3.  * Copyright (C) 1992 Bryan Ford
  4.  *
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or
  8.  * (at your option) any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  * I (the author of MultiPlayer) can be contacted on the Internet at
  20.  * "bryan.ford@m.cc.utah.edu".  See "Player.doc" for other addresses.
  21.  *
  22.  * $Id: flashywin.c,v 4.4 92/07/19 18:07:29 BAF Exp $
  23.  *
  24.  * $Log:    flashywin.c,v $
  25.  * Revision 4.4  92/07/19  18:07:29  BAF
  26.  * Adjustment for putting localdata back into RemindNodes
  27.  * 
  28.  * Revision 4.3  92/07/12  08:27:16  BAF
  29.  * Fixed stupid migration crashing bug
  30.  *
  31.  * Revision 4.2  92/06/21  11:12:56  BAF
  32.  * Migrated regargs to stdargs
  33.  *
  34.  * Revision 4.1  92/06/06  19:56:32  BAF
  35.  * Major_code_cleanup
  36.  *
  37.  * Revision 3.1  92/05/25  07:53:12  BAF
  38.  * GNU-ized.
  39.  *
  40.  *
  41.  */
  42.  
  43.  
  44. /* System includes */
  45. #include <exec/types.h>
  46. #include <exec/tasks.h>
  47. #include <exec/semaphores.h>
  48. #include <exec/execbase.h>
  49. #include <dos/dos.h>
  50. #include <intuition/intuition.h>
  51. #include <libraries/asl.h>
  52. #include <proto/exec.h>
  53. #include <proto/dos.h>
  54. #include <proto/graphics.h>
  55. #include <proto/intuition.h>
  56.  
  57. #include "bry/macros.h"
  58. #include "bry/remind.h"
  59. #include "bry/guido.h"
  60.  
  61. #include "player.h"
  62.  
  63. extern struct ExecBase *SysBase;
  64.  
  65. extern char prefsglob[];
  66.  
  67. extern GuidoSpec spectrumwinspec, scopewinspec, qscopewinspec, notewinspec;
  68. extern short spectrumwinleft, scopewinleft, qscopewinleft, notewinleft;
  69.  
  70. extern char flashactive;
  71. extern struct Task *flashytaskptr;
  72.  
  73. extern struct Task flashytask;
  74. extern struct SignalSemaphore flashysem;
  75.  
  76. struct Gadget *spectrumboxgad;
  77. struct Gadget *scopeboxlgad, *scopeboxrgad;
  78. struct Gadget *noteboxgad;
  79. struct Gadget *qscopeboxltgad, *qscopeboxrtgad, *qscopeboxlbgad;
  80.  
  81. static int close(int remake,struct MPWin *win);
  82.  
  83. static long checkspectrum(long sigmask);
  84. static void spectruminit(void);
  85. struct RastPort *spectrumrastport;
  86. static struct MPWin spectrummpwin = {spectrumwinspec,&spectrumwinleft,spectruminit,
  87.   {0},{{0},checkspectrum,(long)&spectrummpwin},{{0},close,(long)&spectrummpwin},&spectrumrastport};
  88. short spectrumboxleft, spectrumboxtop;
  89.  
  90. static long checkscope(long sigmask);
  91. static void scopeinit(void);
  92. struct RastPort *scoperastport;
  93. static struct MPWin scopempwin = {scopewinspec,&scopewinleft,scopeinit,
  94.   {0},{{0},checkscope,(long)&scopempwin},{{0},close,(long)&scopempwin},&scoperastport};
  95. short scopeboxlleft, scopeboxrleft, scopeboxtop;
  96.  
  97. static long checkqscope(long sigmask);
  98. static void qscopeinit(void);
  99. struct RastPort *qscoperastport;
  100. static struct MPWin qscopempwin = {qscopewinspec,&qscopewinleft,qscopeinit,
  101.   {0},{{0},checkqscope,(long)&qscopempwin},{{0},close,(long)&qscopempwin},&qscoperastport};
  102. short qscopeboxlx, qscopeboxrx, qscopeboxty, qscopeboxby;
  103.  
  104. static long checknote(long sigmask);
  105. static void noteinit(void);
  106. struct RastPort *noterastport;
  107. static struct MPWin notempwin = {notewinspec,¬ewinleft,noteinit,
  108.   {0},{{0},checknote,(long)¬empwin},{{0},close,(long)¬empwin},¬erastport};
  109. short noteboxleft, noteboxtop;
  110.  
  111. static long
  112. close(int remake,struct MPWin *win)
  113. {
  114.   if(win->win)
  115.     {
  116.       ObtainSemaphore(&flashysem);
  117.       *((long*)win->userdata) = 0;
  118.       win->win->RPort->Mask = 0xff; // Kludge to get around bug in 2.04 layers
  119.       closempwin(win);
  120.       if(remake)
  121.         showerr(openmpwin(win));
  122.       flashactive = spectrummpwin.win || scopempwin.win || qscopempwin.win || notempwin.win;
  123.       if((!flashactive) && (flashytaskptr))
  124.         {
  125.           flashytaskptr = 0L;
  126.           RemTask(&flashytask);
  127.         }
  128.       ReleaseSemaphore(&flashysem);
  129.     }
  130.   return(0);
  131. }
  132.  
  133. static void
  134. callback(struct GuidoMessage *im)
  135. {
  136.   extern char flashactive;
  137.  
  138.   if(im->Class == IDCMP_REFRESHWINDOW)
  139.     {
  140.       flashactive = 1;
  141.       if(flashytaskptr)
  142.         Signal(flashytaskptr,SIGBREAKF_CTRL_F);
  143.     }
  144.   standardcallback(im);
  145. }
  146.  
  147. static long
  148. checkspectrum(long sigmask)
  149. {
  150.   if((sigmask & spectrummpwin.sigmask) && GCheckPanel(spectrummpwin.win,callback,0L))
  151.     flashflags &= ~FF_SPECTRUM, GlobPostMod(prefsglob,0);
  152.   return(0);
  153. }
  154.  
  155. static long
  156. checkscope(long sigmask)
  157. {
  158.   if((sigmask & scopempwin.sigmask) && GCheckPanel(scopempwin.win,callback,0L))
  159.     flashflags &= ~FF_SCOPE, GlobPostMod(prefsglob,0);
  160.   return(0);
  161. }
  162.  
  163. static long
  164. checkqscope(long sigmask)
  165. {
  166.   if((sigmask & qscopempwin.sigmask) && GCheckPanel(qscopempwin.win,callback,0L))
  167.     flashflags &= ~FF_QSCOPE, GlobPostMod(prefsglob,0);
  168.   return(0);
  169. }
  170.  
  171. static long
  172. checknote(long sigmask)
  173. {
  174.   if((sigmask & notempwin.sigmask) && GCheckPanel(notempwin.win,callback,0L))
  175.     flashflags &= ~FF_NOTES, GlobPostMod(prefsglob,0);
  176.   return(0);
  177. }
  178.  
  179. static void
  180. spectruminit(void)
  181. {
  182.   spectrumrastport = spectrummpwin.win->RPort;
  183.   spectrumboxleft = spectrumboxgad->LeftEdge+2;
  184.   spectrumboxtop = spectrumboxgad->TopEdge+1;
  185. }
  186.  
  187. static void
  188. scopeinit(void)
  189. {
  190.   scoperastport = scopempwin.win->RPort;
  191.   scopeboxlleft = scopeboxlgad->LeftEdge+2;
  192.   scopeboxrleft = scopeboxrgad->LeftEdge+2;
  193.   scopeboxtop = scopeboxrgad->TopEdge+1;
  194. }
  195.  
  196. static void
  197. qscopeinit(void)
  198. {
  199.   qscoperastport = qscopempwin.win->RPort;
  200.   qscopeboxlx = qscopeboxltgad->LeftEdge+2;
  201.   qscopeboxrx = qscopeboxrtgad->LeftEdge+2;
  202.   qscopeboxty = qscopeboxltgad->TopEdge+1;
  203.   qscopeboxby = qscopeboxlbgad->TopEdge+1;
  204. }
  205.  
  206. static void
  207. noteinit(void)
  208. {
  209.   noterastport = notempwin.win->RPort;
  210.   SetAPen(noterastport,3);
  211.   noteboxleft = noteboxgad->LeftEdge+2;
  212.   noteboxtop = noteboxgad->TopEdge+1;
  213. }
  214.  
  215. /* Unlike the other ...openclose() functions, this does NOT toggle
  216.    any particular window - it just updates the open/closed state of
  217.    all the flashy windows to reflect the state of the main window
  218.    (i.e. all flashy windows close if the main window closes) and
  219.    the flashflags in preferences.  */
  220. char *
  221. flashywinopenclose(void)
  222. {
  223. extern struct Screen *playerscreen;
  224. extern void flashyupdate(void);
  225. char *err = 0L, *e, ff;
  226.  
  227.   ff = flashactive = playerscreen ? flashflags : 0;
  228.  
  229.   if(!flashytaskptr)
  230.     InitSemaphore(&flashysem);
  231.   ObtainSemaphore(&flashysem);
  232.  
  233.   if(ff & FF_SPECTRUM)
  234.     {
  235.       if(!spectrummpwin.win && (e = openmpwin(&spectrummpwin)))
  236.         err = e;
  237.     }
  238.   else
  239.     setfinmpwin(&spectrummpwin);
  240.  
  241.   if(ff & FF_SCOPE)
  242.     {
  243.       if(!scopempwin.win && (e = openmpwin(&scopempwin)))
  244.         err = e;
  245.     }
  246.   else
  247.     setfinmpwin(&scopempwin);
  248.  
  249.   if(ff & FF_QSCOPE)
  250.     {
  251.       if(!qscopempwin.win && (e = openmpwin(&qscopempwin)))
  252.         err = e;
  253.     }
  254.   else
  255.     setfinmpwin(&qscopempwin);
  256.  
  257.   if(ff & FF_NOTES)
  258.     {
  259.       if(!notempwin.win && (e = openmpwin(¬empwin)))
  260.         err = e;
  261.     }
  262.   else
  263.     setfinmpwin(¬empwin);
  264.  
  265.   if((ff) && (!flashytaskptr))
  266.     {
  267.     extern void flashyupdate(void);
  268.  
  269.       flashytask.tc_SPReg = flashytask.tc_SPUpper; /* Always reset the stack pointer */
  270.       if(!AddTask(&flashytask,flashyupdate,0) && (SysBase->LibNode.lib_Version >= 37))
  271.         err = "Not enough memory";
  272.       else
  273.         flashytaskptr = &flashytask;
  274.     }
  275.  
  276.   ReleaseSemaphore(&flashysem);
  277.  
  278.   return(err);
  279. }
  280.  
  281. void
  282. gui_flashywinopenclose(void)
  283. {
  284.   showerr(flashywinopenclose());
  285. }
  286.